package com.example.lenovo.mywechat.homepage.find;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lenovo.mywechat.R;


import java.util.List;

public class GroupListAdapter extends RecyclerView.Adapter<GroupListAdapter.ViewHolder> {

    private List<Group> groupList;

    static  class ViewHolder extends RecyclerView.ViewHolder{

        ImageView groupImage;
        TextView groupName;

        public ViewHolder(View view){
            super(view);
            groupImage = view.findViewById(R.id.group_imageView);
            groupName = view.findViewById(R.id.group_textView);
        }
    }

    public GroupListAdapter(List<Group> group){
        this.groupList = group;
    }
    @NonNull
    @Override
    public GroupListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
       View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.group_list_item,viewGroup,false);
       ViewHolder holder = new ViewHolder(view);
       return  holder;
    }

    @Override
    public void onBindViewHolder(@NonNull GroupListAdapter.ViewHolder viewHolder, int i) {
        Group group = groupList.get(i);
        viewHolder.groupName.setText(group.getGroupname());
        viewHolder.groupImage.setImageDrawable(Drawable.createFromStream(group.getImage().newInput(),null));
    }

    @Override
    public int getItemCount() {
        return groupList.size();
    }
}
